<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>The Index Page</h2>
<button onclick="doBuy()">购买</button>
<span id="result"></span>
<!--
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
-->
<script src="/js/axios.min.js"></script>
<script>
    function doBuy(){
      debugger
      //1.定义请求url(注意对应的是网关的地址)
      let url="http://localhost:9000/nacos/provider/echo/1";
      //2.基于axios框架发送ajax异步请求
      let span=document.getElementById("result");
      axios.get(url)
           .then(function(result){//result.status==200
              console.log(result);
              if(!result.data.status){
                span.innerHTML=result.data;
              }else{
                span.innerHTML=result.data.message;
              }
           })
           .catch(function(error){//服务端没有处理异常，走这里
               if(error.response.status==429){
                   span.innerHTML=error.response.statusText;
               }
           });
    }
</script>
</body>
</html>